package com.starlink.controller.wechat;

import com.starlink.common.WebResponse;
import com.starlink.common.annotation.WebAccess;
import com.github.pagehelper.PageInfo;
import com.starlink.common.annotation.client.weixin.UserPurchaseRes;
import com.starlink.model.request.DepositRecordRequest;
import com.starlink.model.vo.mall.WeixinRefundOrderVO;
import com.starlink.service.DepositRecordService;
import com.starlink.model.vo.DepositRecordVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.SortDefault;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @author zhanghong
 */
@RestController
@RequestMapping("/wechat/depositRecord")
@Api(value = "【小程序端】押金记录模块", tags = {"【小程序端】押金记录模块"})
public class WechatDepositRecordController {

    @Autowired
    private DepositRecordService depositRecordService;


    @WebAccess(login = true)
    @ApiOperation("押金余额查询")
    @PostMapping("/getDeposit")
    public WebResponse<DepositRecordVO> getDeposit(@RequestBody DepositRecordRequest request) {
        return WebResponse.build(depositRecordService.getDeposit(request));
    }

    @WebAccess(login = true)
    @ApiOperation("押金记录分页查询")
    @PostMapping("/pageQuery")
    public WebResponse<PageInfo<DepositRecordVO>> pageQuery(@SortDefault(sort = {"create_time"}, direction = Sort.Direction.DESC) Pageable pageable,
                                                           @RequestBody DepositRecordRequest request) {
        return WebResponse.build(depositRecordService.pageQuery(pageable,request));
    }

    @WebAccess(login = true)
    @ApiOperation("新增押金记录")
    @PostMapping("/add")
    public WebResponse<Boolean> add(@Valid @RequestBody DepositRecordRequest request) {
        return WebResponse.build(depositRecordService.add(request));
    }

    @WebAccess(login = true)
    @ApiOperation("押金充值")
    @PostMapping("/depositCharge")
    public WebResponse<UserPurchaseRes> depositCharge(@Valid @RequestBody DepositRecordRequest request) {
        return WebResponse.build(depositRecordService.depositCharge(request));
    }

    @WebAccess(login = true)
    @ApiOperation("押金退款")
    @PostMapping("/depositRefund")
    public WebResponse<Boolean> depositRefund(@Valid @RequestBody DepositRecordRequest request) {
        return WebResponse.build(depositRecordService.depositRefund(request));
    }

}
